<?php
class User extends AppModel {
    var $displayField = 'user_name';
    var $name = 'User';
    
    var $validate = array(
        'user_name' => array(
     		'rule' => array('minLength', '5'),
 			'message' => 'Mimimum 8 characters long'
    	),
        'email_address' => array('email'),
        'password' => array('alphaNumeric'),
        'active' => array('numeric')
    );
    var $hasAndBelongsToMany = array(
            'Group' => array('className' => 'Group',
                        'joinTable' => 'groups_users',
                        'foreignKey' => 'user_id',
                        'associationForeignKey' => 'group_id',
                        'unique' => true
            )
    );
    
	function findByUsername($u) {
		$result = null ;
		$result = $this->find('first', array('conditions' => array('user_name' => $u)));
		return $result;
	}
}
